#include "CMainMenuState.h"
#include "CGame.h"
#include "COptionMenuState.h"
#include "CGamePlayState.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_DirectSound.h"
#include "SGD Wrappers/CSGD_WaveManager.h"
#include "SGD Wrappers/CSGD_DirectInput.h"

CMainMenuState::CMainMenuState()
{
	m_nCurrSelection = 0;
	
}
CMainMenuState::~CMainMenuState()
{

}
CMainMenuState* CMainMenuState::GetInstance()
{
	static CMainMenuState instance;
	return &instance;
}
bool CMainMenuState::Input()
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_ESCAPE))
	{
		CGame::GetInstance()->ChangeState(NULL);
		return false;
	}
	if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_DOWN))
	{
		
		if(m_nCurrSelection == 5)
			m_nCurrSelection = 0;
		else
			m_nCurrSelection += 1;
	}
	if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_UP))
	{
		
		if(m_nCurrSelection == 0)
			m_nCurrSelection = 5;
		else
			m_nCurrSelection -= 1;
	}
	if(CSGD_DirectInput::GetInstance()->KeyPressedEx(DIK_RETURN))
	{
		if(m_nCurrSelection == 0)
		{
			CGame::GetInstance()->PushState(CGamePlayState::GetInstance());
		}
		else if(m_nCurrSelection == 1)
		{
			CGame::GetInstance()->PushState(COptionMenuState::GetInstance());
		}
		else if(m_nCurrSelection == 2)
		{

		}
		else if(m_nCurrSelection == 3)
		{

		}
		else if(m_nCurrSelection == 4)
		{

		}
		else if(m_nCurrSelection == 5)
		{
			CGame::GetInstance()->ChangeState(NULL);
			return false;
		}
	}
	return true;
}
void CMainMenuState::Enter()
{
	m_nCurrSelection = 0;
	m_nMenuCursor = CSGD_TextureManager::GetInstance()->LoadTexture("resource/SGD_MenuCursor.png");
}
void CMainMenuState::Exit()
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(m_nMenuCursor);
}
void CMainMenuState::Update(float fDelta)
{

}
void CMainMenuState::Render()
{	
	CSGD_Direct3D::GetInstance()->DrawText("Main Menu", 100, 100);
	
	CSGD_TextureManager::GetInstance()->Draw(m_nMenuCursor, 80, (m_nCurrSelection*20) + 150);
	CSGD_Direct3D::GetInstance()->DrawText("Play", 100, 150);
	CSGD_Direct3D::GetInstance()->DrawText("Options", 100, 170);
	CSGD_Direct3D::GetInstance()->DrawText("High Scores", 100, 190);
	CSGD_Direct3D::GetInstance()->DrawText("How To Play", 100, 210);
	CSGD_Direct3D::GetInstance()->DrawText("Credits", 100, 230);
	CSGD_Direct3D::GetInstance()->DrawText("Exit", 100, 250);
}